<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function sendAjax(url) {
            return new Promise((resolve, reject) => {  //执行器函数，同步的回调

                //开启异步任务
                const xhr = new XMLHttpRequest()
                xhr.onreadystatechange = () => {
                    if (xhr.readyState !== 4) return
                    if (xhr.status >= 200 && xhr.status <= 299) {
                        resolve(JSON.parse(xhr.response))
                    } else {
                        reject(new Error('请求失败'))
                    }
                }
                xhr.open('get', url)
                xhr.send()
            })
        }
        sendAjax('https://api.apiopen.top/todayVideo')
            .then(
                value => console.log('onResloved', value),
                reason => console.log('onReject', reason.message),
            )
    </script>
</body>

</html>